package cn.yc.student.controller;

import cn.yc.student.pojo.Student;
import cn.yc.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class Mycontroller {


    @Autowired
    StudentService studentService;

    @RequestMapping("index")
    public String select(Model model){
        List<Student> select = studentService.select();
        model.addAttribute("select",select);
        return "student";
    }
    @RequestMapping("/emp/{id}")
    public String deleteEmp(@PathVariable("id") int id){
        studentService.delete(id);
        return "redirect:/index";
    }

    @GetMapping("/add")
    public String add(){
        return "addStudent";
    }

    @PostMapping("/add")
    public String add(Student student){
        studentService.insert(student);
        return "redirect:/index";
    }


}
